/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Database;

import Models.Room;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author trang_000
 */
public class RoomDAO {
    private Connection con;
    public RoomDAO(){
        con = DBFactory.createConnection("dormitoryv2");
    }
    public List<Room> getRoomListByFloor(int floor){
        List<Room> results = new ArrayList<>();
        try {
            //get parent categories
            String sqlst = "SELECT * FROM room WHERE floor = ?";
            PreparedStatement ps = con.prepareStatement(sqlst);
            ps.setInt(1, floor);

            ResultSet rs = ps.executeQuery();

            while (rs.next()) {
                String name = rs.getString("roomName");
                String description = rs.getString("description");
                int currentMembre = rs.getInt("currentMembre");
                int maximumMembre = rs.getInt("maximumMembre");
                Room temp = new Room(name, floor, currentMembre, maximumMembre);
                //add to results
                results.add(temp);
            }
        } catch (SQLException ex) {
            Logger.getLogger(RoomDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return results;
    }
}
